package com.rinlink.jbcodec.transform;


import com.rinlink.jbcodec.exception.TransformException;

import java.nio.ByteBuffer;
import java.util.List;


public class BooleanListToBytes extends ObjectListToBytess {

    private static byte TRUE = 0x01;
    private static byte FALSE = 0x00;

    public BooleanListToBytes(List<Boolean> list) {
        super(list);
    }

    @Override
    public byte[] transform() throws TransformException {
        List<Boolean> booleans = getList();
        ByteBuffer buffer = ByteBuffer.allocate(booleans.size());
        for (int i = 0; i < booleans.size(); i++)
            buffer.put(booleans.get(i) ? TRUE : FALSE);
        return buffer.array();
    }

}
